import { Routes, Route } from 'react-router-dom'
import { HistoryRouter, history } from './utils/history'
import { lazy, Suspense } from 'react'
import AuthRoute from '@/components/AuthRoute'
import './App.scss'
// 导入页面组件
// 按需导入路由组件
const Login = lazy(() => import('./pages/Login'))
const Layout = lazy(() => import('./pages/Layout'))
const Home = lazy(() => import('./pages/Home'))
const Article = lazy(() => import('./pages/Article'))
const Publish = lazy(() => import('./pages/Publish'))
function App() {
  return (
    <HistoryRouter history={history}>
      <div className='app'>
        <Suspense
          fallback={
            <div
              style={{
                textAlign: 'center',
                marginTop: 200
              }}
            >
              loading...
            </div>
          }
        >
          <Routes>
            <Route path='/' element=
              {
                <AuthRoute>
                  <Layout />
                </AuthRoute>
              }>
              <Route index element={<Home />}></Route>
              <Route path='/article' element={<Article />}></Route>
              <Route path='/publish' element={<Publish />}></Route>
            </Route>
            <Route path='/login' element={<Login />} />
          </Routes>
        </Suspense>
      </div>
    </HistoryRouter>
  )
}

export default App;
